package com.youpingou.controller;

import com.aliyuncs.exceptions.ClientException;
import com.youpingou.domain.User;
import com.youpingou.util.GetRandomCodeUtil;
import com.youpingou.util.SmsUtil;
import com.youpingou.vo.BaseResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @auther Created by yuanxinqi on 2022/9/18
 */
@RestController
@RequestMapping
public class SmsController {
    @Autowired
    private RedisTemplate<String,String> redisTemplate;

    @PostMapping("sms")
    public BaseResult sendSms(@RequestBody User user){
        String mobile = user.getMobile();
        String code = GetRandomCodeUtil.randomCode();
        code = "123456";
//        try {
//            SmsUtil.sendSms(mobile,code);
//        } catch (ClientException e) {
//            e.printStackTrace();
//        }
        redisTemplate.opsForValue().set(mobile,code);
        return BaseResult.ok();
    }

}